/*
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 */
function onAddNewCustomer(frmID,page) {
	var newId = '';
	var success = '';
	$(frmID).request( {
			asynchronous: false,
			parameters: $(frmID).serialize(true),
			onComplete: function(transport) { 
				var response = transport.responseText || "";
				var pos=response.indexOf('<!');
				content=response.substring(0,pos);
		    	
		    	if(content != "")
		    	{
		    		obj = content.evalJSON();
		    		ret=0;
					arr = obj.message;
					success = obj.code;
					for (key in arr){
						var diverr= document.getElementById('err_'+key);
						if(diverr && arr[key]!=""){
							diverr.update(arr[key]);
							diverr.style.display ="block";
               			//alert(key); 
						}else{
							diverr.update('');	
							diverr.style.display ="none";	
						}
					}
					
		    	}
			}
		});
	if(success=="0")
		document.location = page;
}

function onDeleteCustomer(url, CustomerId, resp) {
	var isOK = -1;
	if(!confirm('Are you sure you want to delete the Customer with Id:' + CustomerId)) {
		return false;
	}
	
	new Ajax.Request(url, {
	  method: 'POST',
	  asynchronous: false,
	  parameters:'act=delcustomer&id=' + CustomerId,
	  onSuccess: function(transport) {
			var response = transport.responseText || "";
			var pos=response.indexOf('<!');
			content=response.substring(0,pos);
			obj = content.evalJSON();

    		if(obj == null) {
    			$(resp).innerHTML = 'Something wrong! Reponsed string is: ' + response;
    		}
    		
    		isOK = obj.code;
		
    		$(resp).update(obj.message);
		}
	});

	$(resp).style.display = 'inherit';
	Fat.fade_element(resp, null, 1500, null, null);

	if(isOK == 0){
		rowID = 'customer-' + CustomerId;
		Fat.fade_element(rowID, null, 1000, "#f22", null);
		setTimeout("$(rowID).remove()", 1000);
		
	}				
}


function onEditCustomer(frmID, page) {
	var newId = '';
	var ret = null;
	var message = null;
	var success = '';
	$(frmID).request( {
			asynchronous: false,
			parameters: $(frmID).serialize(true),
			onComplete: function(transport) { 
				var response = transport.responseText || "";
				var pos=response.indexOf('<!');
				content=response.substring(0,pos);

		    	if(content != "")
		    	{
		    		obj = content.evalJSON();
		    		ret=0;
					arr = obj.message;
					success = obj.code;
					for (key in arr){
						var diverr= document.getElementById('err_'+key);
						if(diverr && arr[key]!=""){
							diverr.update(arr[key]);
							diverr.style.display ="block";
               			//alert(key); 
						}else{
							diverr.update('');	
							diverr.style.display ="none";	
						}
					}
					
		    	}
			}
	});
	if(success=="0")
		document.location = page;
	return false;
}

function onCheckError(Id, url,passID)
{
	var post = '';
	var pass= document.getElementById(passID);
	var frame= document.getElementById('err_'+Id.id);
	if(frame.style.display=="block"){
		if(passID!='')
			post = '&'+passID+'='+pass.value;
		new Ajax.Request(url, {
		  method: 'post',
		  asynchronous: false,
		  parameters:'act=checkerror&'+Id.id+'=' + Id.value+post,
		  onSuccess: function(transport) {
					var response = transport.responseText || "";
					var pos=response.indexOf('<!');
					content=response.substring(0,pos);
					//alert(content);
					if(content != "")
					{
						obj = content.evalJSON();
						arr = obj.message;
						for (key in arr){
							var diverr= document.getElementById('err_'+key);
								if(key==Id.id){	
									if(diverr && arr[key]!=""){
										diverr.update(arr[key]);
										diverr.style.display ="block";
										
									}else{
										diverr.update('Ok');
										diverr.className='check_ok';
										
										//diverr.style.display ="none";	
									}
								}
						}
						
					}
			}
		});
	}
	Id.className ="textinput";
	return false;
}

function onKey(ID,class)
{
	ID.className=class;
}
